//
// Created by yunnan xu on 2020/11/10.
//

#ifndef ANDROIDGRAPHICSDEMOS_ENGINECORE_H
#define ANDROIDGRAPHICSDEMOS_ENGINECORE_H

#include "android_native_app_glue.h"
#include <EGL/egl.h>
#include <GLES3/gl32.h>
#include <android/log.h>
#include <jni.h>
#include <vector>
#include <memory>
#include <chrono>

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "RenderLib", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "RenderLib", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "RenderLib", __VA_ARGS__))

/**
 * Our saved state data.
 */


class Pass;
class Buffer;

class RenderEngine {
public :

    virtual void ShaderSetup() = 0;
    virtual void Draw() = 0;
    virtual void PipelineSetup() = 0;
    virtual void SceneSetup(const char * scene_name) = 0;

    std::shared_ptr<Pass> GetPass(int index) {return passList[index];}

protected:
    std::vector<std::shared_ptr<Pass>> passList;
};


class GLESEngine : public RenderEngine {

public:

    GLESEngine();

    struct android_app* app{};

    int animating{};
    EGLDisplay display{};
    EGLSurface surface{};
    EGLContext context{};
    int32_t width;
    int32_t height;

    android_app * GetAndroidAppPtr() {return app;}

    virtual void ShaderSetup();
    virtual void PipelineSetup();
    virtual void Draw();
    virtual void SceneSetup(const char * scene_name);

    std::chrono::system_clock::time_point startEngineTime;
    std::chrono::system_clock::time_point lastTickEngineTime;


};

extern GLESEngine * g_engine;

#endif //ANDROIDGRAPHICSDEMOS_ENGINECORE_H
